package common.utils;

import java.io.IOException;

import common.files.FileHelper;

public class LogUtil {

	public static void print(int i){
		print(String.valueOf(i));
	}

	public static void println(int i){
		println(String.valueOf(i));
	}

	public static void print(Object obj){
		System.out.print(obj);
		write(obj, 1);
	}

	public static void println(Object obj){
		System.out.println(obj);
		write(obj, 2);
	}

	public static void write(Object obj, int i){
		String str = new String();
		if (obj == null) {
			str = "";
		} else {
			str = obj.toString();
		}

		String filename = "logs\\log" + DateTimeUtil.getTimeformat() + ".log";

		FileHelper file = new FileHelper();

		StringBuffer content = new StringBuffer();

		if (i == 2) {
			content.append(str + "\n" + DateTimeUtil.getTimeformat(3));
		} else {
			content.append(str);
		}

		try {
			file.writefile(filename, content.toString(), true);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.err.println("log file write error!\n" + e.getMessage());
			e.printStackTrace();
		}

	}
}
